/*
 * @Descripttion: 
 * @version: 
 * @Author: zhaoxiaodong
 * @Date: 2020-09-01 10:08:02
 * @LastEditors  : 陈韵同
 * @LastEditTime : 2020-11-25 11:15:54
 */

const getValueByPath = function (object, key) {
  key = key || '';
  const paths = key.split('.');
  let current = object;
  let result = null;
  for (let i = 0, j = paths.length; i < j; i++) {
    const path = paths[i];
    if (!current) break;

    if (i === j - 1) {
      result = current[path];
      break;
    }
    current = current[path];
  }
  return result;
};

const getters = {
  userInfo: state => state.user.userInfo,
  token: state => state.app.token,
  msg: state => state.appstore.msg,
  getUserInfoByKey: state => key => {
    return getValueByPath(state.user.userInfo, key);
  }
}

export default getters;